package com.ph.irp.sell.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Date;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.ph.irp.model.PSellSellorderdetail;
import com.ph.irp.sell.dao.SellOrderDetailDAO;
import com.ph.util.DBUtil;
import com.ph.util.DateUtil;

public class SellOrderDetailDAOImpl implements SellOrderDetailDAO {
private ComboPooledDataSource dataSource; 
Connection con = null;
PreparedStatement pStmt = null;
ResultSet rs = null;
	@Override
	public void addSellOrderDetail(PSellSellorderdetail sellOrderDetail)
			throws Throwable {
	try{
		
		StringBuilder sb = new StringBuilder();
		sb.append("insert into  p_sell_sellorderdetail(sellOrderId, MaterialID, measureUnitId, BasicUnitAmount, Amount,SimplePrice, IncludeTaxPrice, money, TaxPercent, discount,DiscountPrice, AcctualIncludeTaxPrice,sellTaxMoney,TotalMoney,deliveryDate, memo,outStorageAmountBasic,outStorageAmount, invoiceAmountBasic, invoiceAmount, produceAmountBasic, produceAmount,sourceBillCode,haveInStorageAmout)");
		sb.append("values (");
		sb.append(sellOrderDetail.getSellOrderId()).append(",");//sellOrderId销售订单id
		sb.append(sellOrderDetail.getMaterialID()).append(",");//MaterialID物料id
		sb.append(sellOrderDetail.getMeasureUnitId()).append(",");//measureUnitId单位id
		sb.append(sellOrderDetail.getBasicUnitAmount()).append(",");//BasicUnitAmount基本单位数量
		sb.append(sellOrderDetail.getAmount()).append(",");//Amount数量
		sb.append(sellOrderDetail.getSimplePrice()).append(",");//SimplePrice
		sb.append(sellOrderDetail.getIncludeTaxPrice()).append(",");//IncludeTaxPrice
		sb.append(sellOrderDetail.getMoney()).append(",");//money
		sb.append(sellOrderDetail.getTaxPercent()).append(",");//TaxPercent
		sb.append(sellOrderDetail.getDiscount()).append(",");//discount
		sb.append(sellOrderDetail.getDiscountPrice()).append(",");//DiscountPrice
		sb.append(sellOrderDetail.getAcctualIncludeTaxPrice()).append(",");//AcctualIncludeTaxPrice
		sb.append(sellOrderDetail.getSellTaxMoney()).append(",");//sellTaxMoney
		sb.append(sellOrderDetail.getTotalMoney()).append(",");//TotalMoney
		sb.append("'").append(sellOrderDetail.getDeliveryDate()).append("',");//deliveryDate
		sb.append("'").append(sellOrderDetail.getMemo()).append("'").append(",");//memo
		sb.append(sellOrderDetail.getOutStorageAmountBasic()).append(",");//outStorageAmounstBasic
		sb.append(sellOrderDetail.getOutStorageAmount()).append(",");//outStorageAmount
		sb.append(sellOrderDetail.getInvoiceAmountBasic()).append(",");//invoiceAmountBasic
		sb.append(sellOrderDetail.getInvoiceAmount()).append(",");//invoiceAmount
		sb.append(sellOrderDetail.getProduceAmountBasic()).append(",");//produceAmountBasic
		sb.append(sellOrderDetail.getProduceAmount()).append(",");//produceAmount
		sb.append("'").append(sellOrderDetail.getSourceBillCode()).append("'").append(",");//sourceBillCode
		sb.append(sellOrderDetail.getHaveInStorageAmout());//haveInStorageAmout
		sb.append(")");
		con = dataSource.getConnection();
		con.setAutoCommit(false);
		pStmt = con.prepareStatement(sb.toString());
		pStmt.executeUpdate();
		con.commit();
			}
	catch(Exception e){
		throw new Exception(e.getMessage());
	}
	finally{
		try {
			DBUtil.setNullObject(con, pStmt, rs);
		} catch (Exception ex) {
			throw new Exception(ex.getMessage());
		}
	}

	}
	public ComboPooledDataSource getDataSource() {
		return dataSource;
	}
	public void setDataSource(ComboPooledDataSource dataSource) {
		this.dataSource = dataSource;
	}
	public Connection getCon() {
		return con;
	}
	public void setCon(Connection con) {
		this.con = con;
	}
	public PreparedStatement getPStmt() {
		return pStmt;
	}
	public void setPStmt(PreparedStatement stmt) {
		pStmt = stmt;
	}
	public ResultSet getRs() {
		return rs;
	}
	public void setRs(ResultSet rs) {
		this.rs = rs;
	}

}
